package site.frame.ftl;

import org.apache.commons.lang.CharEncoding;
import org.apache.commons.lang.StringUtils;
import site.config.CommonConfig;

import java.io.UnsupportedEncodingException;

public abstract class FtlFunctions {
    /**
     * 为传入资源路径自动增加版本号.
     *
     * @param resPath 资源路径
     * @return 增加版本号的路径
     */
    public static String res(String resPath) {
        StringBuffer res = new StringBuffer(CommonConfig.RES_PATH)
                .append("/")
                .append(StringUtils.removeStart(resPath, "/"))
                .append("?resVer=").append("");
        return res.toString();
    }


    /**
     * @param in
     * @return
     * @throws java.io.UnsupportedEncodingException
     */
    public static String encode(String in) throws UnsupportedEncodingException {
        return java.net.URLEncoder.encode(in, CharEncoding.UTF_8);
    }

    /**
     * @param in
     * @return
     * @throws java.io.UnsupportedEncodingException
     */
    public static String utfTrans(byte[] in) throws UnsupportedEncodingException {
        return new String(in,"UTF-8");
    }
}
